package com.starchen.optimalselection.common.utils;

import lombok.Data;

@Data
public class Result<T> {

    private Integer code;
    private String message;
    private T data;

    /**
     * 构造函数私有化
     */
    private Result(){}

    /**
     * 返回成功结果
     * @return
     */
    public static Result success(){
        Result result = new Result();
        result.setCode(ResponseEnum.SUCCESS.getCode());
        result.setMessage(ResponseEnum.SUCCESS.getMessage());
        return result;
    }

    /**
     * 返回成功结果
     * @return
     */
    public static <T> Result success(T data){
        Result result = new Result();
        result.setCode(ResponseEnum.SUCCESS.getCode());
        result.setMessage(ResponseEnum.SUCCESS.getMessage());
        result.setData(data);
        return result;
    }

    /**
     * 返回失败结果
     * @return
     */
    public static Result error(){
        Result r = new Result();
        r.setCode(ResponseEnum.ERROR.getCode());
        r.setMessage(ResponseEnum.ERROR.getMessage());
        return r;
    }

    /**
     * 返回失败结果
     * @return
     */
    public static Result error(ResponseEnum responseEnum){
        Result r = new Result();
        r.setCode(responseEnum.getCode());
        r.setMessage(responseEnum.getMessage());
        return r;
    }

    /**
     * 返回失败结果
     * @return
     */
    public static Result error(int code, String message){
        Result r = new Result();
        r.setCode(code);
        r.setMessage(message);
        return r;
    }

}
